<?php defined('SYSPATH') or die(); ?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>对账明细-思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css,order.css'); }
    {php echo Common::getScript("jquery.buttonbox.js,choose.js,hdate/hdate.js"); }
    {php echo Common::getCss('hdate.css','js/hdate'); }
</head>
<body style="overflow:hidden">

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:hidden">
            <div class="fl select-box w100 mt-3 ml-10">
                <select name="channel_id" data-fieldname="channel_id" onchange="toChannel(this)" class="select">
                    <option value="0">销售渠道</option>
                    {loop $channel_list $key $v}
                    <option value="{$v['id']}">{$v['title']}</option>
                    {/loop}
                </select>
            </div>
            <div class="fl select-box w100 mt-3 ml-10">
                <select name="modules" class="select" id="modules" onchange="toProduct(this)">
                    <option value="">产品类别</option>
                    {loop $modules $row}
                    <option value="{$row['id']}" data-py="{$row['maintable']}" data-menuid="{$row['menuid']}">
                        {$row['modulename']}
                    </option>
                    {/loop}
                </select>
            </div>
            <div class="fl select-box w100 mt-3 ml-10">
                <select name="type" onchange="togType(this)" class="select" id="type">
                    <option value="">类型</option>
                    <option value="1">收入</option>
                    <option value="2">支出</option>
                </select>
            </div>
            <div class="cfg-search-bar">
                <div class="cfg-header-search derive_tb">
                    <div class="fl mt-5 mr-10">时间:</div>
                    <input type="text" value="" id="starttime" placeholder="开始日期" autocomplete="off"
                           style="height: 28px;padding:0 5px" class="time_box" onclick="calendar.show({ id: this })"/>

                    <input type="text" id="endtime" class="time_box" placeholder="结束日期" autocomplete="off"
                           style="height: 28px;margin-left:3px;padding:0 5px" onclick="calendar.show({ id: this })"/>
                </div>
                <div class="cfg-header-search">
                    <a href="javascript:;" class="search-btn" onclick="searchKeyword()">搜索</a>
                </div>
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10 btn_excel">导出Excel</a>
            </div>
            <div id="product_grid_panel" class="content-nrt">

            </div>
        </td>
    </tr>
</table>

<script>

    window.display_mode = 1;	//默认显示模式
    window.product_kindid = 0;  //默认目的地ID

    Ext.onReady(
        function () {
            Ext.tip.QuickTipManager.init();
            //产品store
            window.product_store = Ext.create('Ext.data.Store', {

                fields: [
                    'id',
                    'addtime',
                    'amount',
                    'type',
                    'type_desc',
                    'remark',
                    'order_id',
                    'typeid',
                    'channel_name',
                    'ordersn'
                ],

                proxy: {
                    type: 'ajax',
                    api: {
                        read: SITEURL + '{$prefix_url}/check/index/action/read/'  //读取数据的URL
                    },
                    reader: {
                        type: 'json',   //获取数据的格式
                        root: 'lists',
                        totalProperty: 'total'
                    }
                },

                remoteSort: true,
                pageSize: 20,
                autoLoad: true,
                listeners: {
                    load: function (store, records, successful, eOpts) {
                        if (!successful) {
                            ST.Util.showMsg("{__('norightmsg')}", 5, 1000);
                        }
                        var pageHtml = ST.Util.page(store.pageSize, store.currentPage, store.getTotalCount(), 10);
                        $("#line_page").html(pageHtml);
                        window.product_grid.doLayout();
                        $(".pageContainer .pagePart a").click(function () {
                            var page = $(this).attr('page');
                            product_store.loadPage(page);
                        });

                    }
                }

            });

            //产品列表
            window.product_grid = Ext.create('Ext.grid.Panel', {
                store: product_store,
                renderTo: 'product_grid_panel',
                border: 0,
                width: "100%",
                bodyBorder: 0,
                bodyStyle: 'border-width:0px',
                scroll: 'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "",
                    items: [
                        {
                            xtype: 'panel',
                            id: 'listPagePanel',
                            html: '<div id="line_page"></div>'
                        },
                        {
                            xtype: 'combo',
                            fieldLabel: '每页显示数量',
                            width: 170,
                            labelAlign: 'right',
                            forceSelection: true,
                            value: 20,
                            store: {
                                fields: ['num'], data: [
                                    {num: 20},
                                    {num: 40},
                                    {num: 60}
                                ]
                            },
                            displayField: 'num',
                            valueField: 'num',
                            listeners: {
                                select: changeNum
                            }
                        }

                    ],

                    listeners: {
                        single: true,
                        render: function (bar) {
                            var items = this.items;
                            bar.insert(0, Ext.create('Ext.toolbar.Fill'));
                        }
                    }
                }),
                columns: [
                    {
                        text: '时间' + ST.Util.getGridHelp('rcs_detail_time'),
                        width: '15%',
                        dataIndex: 'addtime',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            if (value == 0) {
                                return '<span data-area="无"></span>';
                            }
                            var date = new Date(value * 1000);
                            return '<span>' + Ext.Date.format(date, 'Y-m-d H:i:s') + '</span>';
                        }

                    },
                    {
                        text: '营业收入',
                        width: '10%',
                        dataIndex: 'amount',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            return "{Currency_Tool::symbol()}"+value;
                        }

                    },
                    {
                        text: '收支',
                        width: '10%',
                        dataIndex: 'type',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            var typeName = value == 1 ? '收入' : '支出';
                            return '<span>' + typeName + '</span>';
                        }
                    },


                    {
                        text: '收支类型' + ST.Util.getGridHelp('cw_income_and_expand_state'),
                        width: '20%',
                        dataIndex: 'type_desc',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            return value ? value : '-';
                        }

                    },
                    {
                        text: '订单号',
                        width: '20%',
                        dataIndex: 'ordersn',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            if (value) {
                                var orderid = record.get('order_id');
                                var typeid = record.get('typeid');
                                var channel_name = record.get('channel_name');
                                var ordersn = value;
                                return "<a href='javascript:void(0);' class='btn-link' onclick=\"order_view(" + orderid + "," + typeid + ", '" + channel_name + "', '" + ordersn + "')\">" + value + "</a>"
                            } else {
                                return '-'
                            }

                        }

                    },

                    {
                        text: '备注',
                        width: '25%',
                        dataIndex: 'remark',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            return value ? value : '-';
                        }

                    }
                ],
                listeners: {
                    boxready: function () {
                        var height = Ext.dom.Element.getViewportHeight();
                        this.maxHeight = height - 76;
                        this.doLayout();
                    },
                    afterlayout: function (grid) {

                    }
                },
                plugins: [
                    Ext.create('Ext.grid.plugin.CellEditing', {
                        clicksToEdit: 2,
                        listeners: {}
                    })
                ],
                viewConfig: {
                    enableTextSelection: true
                }
            });
        });

    //实现动态窗口大小
    Ext.EventManager.onWindowResize(function () {
        var height = Ext.dom.Element.getViewportHeight();
        var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
        if (data_height > height - 76)
            window.product_grid.height = (height - 76);
        else
            delete window.product_grid.height;
        window.product_grid.doLayout();
    });

    //按进行搜索
    function searchKeyword() {
        var starttime = $('#starttime').val();
        var endtime = $('#endtime').val();
        window.product_store.getProxy().setExtraParam('startdate', starttime);
        window.product_store.getProxy().setExtraParam('enddate', endtime);
        window.product_store.loadPage(1);
    }

    function toProduct(e) {
        var modules_id = $(e).val();
        window.product_store.getProxy().setExtraParam('modules_id', modules_id);
        window.product_store.loadPage(1);
    }
    function toChannel(e) {
        var channel_id = $(e).val();
        window.product_store.getProxy().setExtraParam('channel_id', channel_id);
        window.product_store.loadPage(1);
    }

    function togType(ele) {
        var type_id = $(ele).val();
        window.product_store.getProxy().setExtraParam('type', type_id);
        window.product_store.loadPage(1);
    }

    //切换每页显示数量
    function changeNum(combo, records) {
        var pagesize = records[0].get('num');
        window.product_store.pageSize = pagesize;
        window.product_store.loadPage(1);
    }

    //订单详情
    function order_view(id, typeid, pdt_type, ordersn) {
        var py = $('#modules').find('option[value="' + typeid + '"]');
        var url = SITEURL + py.attr('data-py') + "/admin/order/view/id/" + id + "/typeid/" + typeid;

        if (py.attr('data-py') == 'model_archive') {
            url = SITEURL + '/order/view/id/' + id + '/typeid/' + typeid;
        }
        url += '/menuid/' + py.attr('data-menuid');
        ST.Util.addTab(pdt_type + '订单：' + ordersn, url, 1);
    }

    //导出excel
    $(".btn_excel").click(function () {
        var url = SITEURL + "{$prefix_url}/check/excel";
        ST.Util.showBox('收支明细生成excel', url, 600, 380, function () {
        });
    })

</script>
</body>
</html>
